

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="运行环境  Ubuntu 21.04 Docker 20.10.7  Docker Compose Docker-Compose是Docker官方的开源项目，负责实现对Docker容器集群的快速编排。 Compose是Doker公司推出的一个工具软件，可管理多个Docker容器组成一个应用。使用时需定义YAML格式的配置文件docker-compose.yml，写出多个容器之间的调用关系，然后只需">
<meta property="og:type" content="article">
<meta property="og:title" content="Docker 笔记4 compose 容器编排">
<meta property="og:url" content="http://example.com/2022/04/09/Docker%20%E7%AC%94%E8%AE%B04%20Compose%20%E5%AE%B9%E5%99%A8%E7%BC%96%E6%8E%92/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="运行环境  Ubuntu 21.04 Docker 20.10.7  Docker Compose Docker-Compose是Docker官方的开源项目，负责实现对Docker容器集群的快速编排。 Compose是Doker公司推出的一个工具软件，可管理多个Docker容器组成一个应用。使用时需定义YAML格式的配置文件docker-compose.yml，写出多个容器之间的调用关系，然后只需">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/2fa6cfefe255498bab113aeaea2419d8.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/9abd4f6c93a8486f873bfe5f513c3e9d.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/345510a1150f43fa99359f48ea2f5124.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/a69563f0e1ec4eaca85a9dba6c9c6925.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/bacedae7543b4ff9adf5de9729e0fc05.png">
<meta property="article:published_time" content="2022-04-09T02:34:52.000Z">
<meta property="article:modified_time" content="2022-08-22T15:43:08.398Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="Docker">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/2fa6cfefe255498bab113aeaea2419d8.png">
  
  
  
  <title>Docker 笔记4 compose 容器编排 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Docker 笔记4 compose 容器编排"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-04-09 10:34" pubdate>
          2022年4月9日 上午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          3.8k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          32 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Docker 笔记4 compose 容器编排</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <h1 id="运行环境"><a href="#运行环境" class="headerlink" title="运行环境"></a>运行环境</h1><hr>
<ul>
<li>Ubuntu 21.04</li>
<li>Docker 20.10.7</li>
</ul>
<h1 id="Docker-Compose"><a href="#Docker-Compose" class="headerlink" title="Docker Compose"></a>Docker Compose</h1><hr>
<p>Docker-Compose是Docker官方的开源项目，负责实现对Docker容器集群的快速编排。</p>
<p>Compose是Doker公司推出的一个工具软件，可管理多个Docker容器组成一个应用。使用时需定义YAML格式的配置文件docker-compose.yml，写出多个容器之间的调用关系，然后只需要一个命令就能同时启动或关闭这些容器。</p>
<p>Compose支持用户通过一个单独的docker-compose.yml模板文件（YAML格式）来定义一组相关联的应用容器为一个项目（project）。</p>
<p><a target="_blank" rel="noopener" href="https://docs.docker.com/compose/compose-file/compose-file-v3/">DockerComposeFileV3官方参考文档</a></p>
<p><a target="_blank" rel="noopener" href="https://docs.docker.com/compose/install/">Docker官方Compose安装帮助文档</a></p>
<h1 id="安装-Docker-Compose"><a href="#安装-Docker-Compose" class="headerlink" title="安装 Docker - Compose"></a>安装 Docker - Compose</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo curl -L <span class="hljs-string">&quot;https://github.com/docker/compose/releases/download/1.29.2/docker-compose-<span class="hljs-subst">$(uname -s)</span>-<span class="hljs-subst">$(uname -m)</span>&quot;</span> -o /usr/local/bin/docker-compose</span><br></code></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo <span class="hljs-built_in">chmod</span> +x /usr/local/bin/docker-compose</span><br></code></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker compose --version</span><br></code></pre></td></tr></table></figure>
<p>卸载docker compose（参照官网）</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo <span class="hljs-built_in">rm</span> /usr/local/bin/docker-compose</span><br></code></pre></td></tr></table></figure>

<h1 id="Docker-Compose两要素"><a href="#Docker-Compose两要素" class="headerlink" title="Docker Compose两要素"></a>Docker Compose两要素</h1><hr>
<p>一文件（docker-compose.yml），两要素 service服务、project工程</p>
<h1 id="Docker-轻量级可视化工具Portainer"><a href="#Docker-轻量级可视化工具Portainer" class="headerlink" title="Docker 轻量级可视化工具Portainer"></a>Docker 轻量级可视化工具Portainer</h1><hr>
<p><a target="_blank" rel="noopener" href="https://www.portainer.io/">portainer官方网址</a></p>
<p>官方介绍</p>
<blockquote>
<p>1.Portainer 可以部署在任何 K8s、Docker 或 Swarm 环境之上。它在云端、本地和边缘无缝运行，为您提供所有容器的统一视图。<br>2. 凭借丰富的治理和控制，Portainer 让平台管理员可以轻松地集中管理 和 保护多集群环境。<br>3.通过其强大的 GUI（和&#x2F;或广泛的 API），Portainer 使开发人员能够部署、管理容器化应用程序并对其进行故障排除，而无需深厚的 Kubernetes 专业知识。<br>4.Portainer 让 DevOps 团队有机会构建简化的、基于 Git 的自动化工作流程，从而提高生产力并减少错误。</p>
</blockquote>
<p>portainer的两个版本：<br>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/710d9e851add4064bf26f2a9906de5d9.png#pic_center">https://img-blog.csdnimg.cn/710d9e851add4064bf26f2a9906de5d9.png#pic_center</a> #&#x3D; 60%x)</p>
<p>使用 Docker 创建portainer最新版本的容器</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker run -d -p 8000:8000 -p 9000:9000 \</span><br><span class="language-bash">--name portainer \</span><br><span class="language-bash">--restart always \</span><br><span class="language-bash">-v /var/run/docker.sock:/var/run/docker.sock \</span><br><span class="language-bash">-v /opt/module/docker/portainer_data:/data \</span><br><span class="language-bash">portainer/portainer</span><br></code></pre></td></tr></table></figure>

<p>注：这里的–restart always参数使得创建的容器每次都自动启动</p>
<p>接下来通过访问 <code>http://docker宿主机ip:9000</code>端口号进行访问</p>
<p>首次进入web页面需要设置admin的密码（需要八位以及以上）<br><img src="https://img-blog.csdnimg.cn/2fa6cfefe255498bab113aeaea2419d8.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>接下来根据需要选择连接的模式</p>
<p><img src="https://img-blog.csdnimg.cn/9abd4f6c93a8486f873bfe5f513c3e9d.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>这里笔者暂时用来管理本地的docker，所以就选择了第一个本地模式</p>
<p><img src="https://img-blog.csdnimg.cn/345510a1150f43fa99359f48ea2f5124.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>如图，登录成功后会显示当前docker宿主机包括docker的一些镜像、容器、容器卷、网关的信息，在这个web页面除了查询这些信息，同时也支持增删改这三个操作，多用用很快就熟练了，这样就保证就算我们不知道docker的相关命令，通过web的这些可视化页面操作，同样可以熟悉docker的容器管理。</p>
<p>其中的<code>Stacks</code>表示使用docker-compose编排的容器</p>
<p>paortainer更方便的一点在于，它可以直接查看容器的运行日志、网关信息、资源占用情况、甚至可以直接在web页面进入docker容器进行shell终端的操作</p>
<h1 id="Docker-容器监控CIG"><a href="#Docker-容器监控CIG" class="headerlink" title="Docker 容器监控CIG"></a>Docker 容器监控CIG</h1><p>CIG即 <a target="_blank" rel="noopener" href="https://github.com/google/cadvisor">CAdvisor</a> + <a target="_blank" rel="noopener" href="https://www.influxdata.com/">InfluxDB</a> + <a target="_blank" rel="noopener" href="https://grafana.com/">Granfana</a>三个框架的缩写。</p>
<p>docker stats 命令可以很方便的看到当前宿主机上所有容器的CPU、内存以及网络流量等数据，一般小公司就够用。</p>
<p>但docker stats统计结果只能是当前宿主机的全部容器，数据资料是实时的，没有地方存储、没有健康指标过线预警等功能。</p>
<p><img src="https://img-blog.csdnimg.cn/a69563f0e1ec4eaca85a9dba6c9c6925.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="Cadvisor"><a href="#Cadvisor" class="headerlink" title="Cadvisor"></a>Cadvisor</h2><p>CAdvisor是一个容器资源监控工具，包括容器的内存、CPU、网络IO、磁盘IO等信息，同时提供WEB页面用于查看容器的实时运行状态。</p>
<p>CAdvisor默认存储2分钟的数据，而且只是针对单物理机。</p>
<p>不过，CAdvisor提供了很多数据集成接口，例如支持InfluxDB、Redis、Kafka、Elasticsearch等框架。</p>
<p>总结，CAdvisor功能主要有以下两个：</p>
<ul>
<li>展示Host和容器两个层次的监控数据</li>
<li>展示历史变化数据</li>
</ul>
<h2 id="InfluxDB"><a href="#InfluxDB" class="headerlink" title="InfluxDB"></a>InfluxDB</h2><p>InfluxDB是用Go语言编写的一个开源分布式时序、事件和指标数据库，无需外部依赖。</p>
<p>CAdvisor默认只在本机保存最近两分钟的数据，为了持久化存储数据和统一收集展示监控数据，需要将数据存储到InfluxDB中。InfluxDB是一个时序数据库，专门用于存储时序相关数据，很适合存储CAdvisor的数据。而且，CAdvisor本身就提供了InfluxDB的集成方法。</p>
<p>总结，InfluxDB功能主要有以下三个：</p>
<ul>
<li>基于时间序列，支持与时间有关的相关函数（如最大、最小、求和等）</li>
<li>可度量性，可以实时对大量数据进行计算</li>
<li>基于事件：它支持任意的事件数据</li>
</ul>
<h2 id="Granfana"><a href="#Granfana" class="headerlink" title="Granfana"></a>Granfana</h2><p>Grafana是一个开源的数据监控分析可视化平台，支持多种数据源配置（比如InfluxDB、MySQL、Elasticsearch、OpenTSDB、Graphite等）和丰富的插件以及模板功能，支持图表权限控制和报警</p>
<p>Grafana主要的特点：</p>
<ul>
<li>灵活丰富的图形化选项</li>
<li>可以混合多种风格</li>
<li>支持白天和夜间模式</li>
<li>支持多个数据源</li>
</ul>
<h2 id="使用docker-compose部署CIG容器"><a href="#使用docker-compose部署CIG容器" class="headerlink" title="使用docker-compose部署CIG容器"></a>使用docker-compose部署CIG容器</h2><p>新建docker宿主机存储CIG信息的目录，在当前目录下编写docker-compose.yml</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo <span class="hljs-built_in">mkdir</span> /opt/module/cig</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo vim docker-compose.yml</span><br></code></pre></td></tr></table></figure>

<p><code>docker-compose.yml</code></p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-attr">version:</span> <span class="hljs-string">&#x27;3.1&#x27;</span><br> <br><span class="hljs-attr">volumes:</span><br>  <span class="hljs-attr">grafana_data:</span> &#123;&#125;<br> <br><span class="hljs-attr">services:</span><br> <span class="hljs-attr">influxdb:</span><br>  <span class="hljs-attr">image:</span> <span class="hljs-string">tutum/influxdb:0.9</span><br>  <span class="hljs-attr">restart:</span> <span class="hljs-string">always</span><br>  <span class="hljs-attr">environment:</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">PRE_CREATE_DB=cadvisor</span><br>  <span class="hljs-attr">ports:</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">&quot;8083:8083&quot;</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">&quot;8086:8086&quot;</span><br>  <span class="hljs-attr">volumes:</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">./data/influxdb:/data</span><br> <br> <span class="hljs-attr">cadvisor:</span><br>  <span class="hljs-attr">image:</span> <span class="hljs-string">google/cadvisor</span><br>  <span class="hljs-attr">links:</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">influxdb:influxsrv</span><br>  <span class="hljs-attr">command:</span> <br>    <span class="hljs-bullet">-</span> <span class="hljs-string">storage_driver=influxdb</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">storage_driver_db=cadvisor</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">storage_driver_host=influxsrv:8086</span><br>  <span class="hljs-attr">restart:</span> <span class="hljs-string">always</span><br>  <span class="hljs-attr">ports:</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">&quot;8080:8080&quot;</span><br>  <span class="hljs-attr">volumes:</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">/:/rootfs:ro</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">/var/run:/var/run:ro</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">/sys:/sys:ro</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">/var/lib/docker/:/var/lib/docker:ro</span><br> <br> <span class="hljs-attr">grafana:</span><br>  <span class="hljs-attr">image:</span> <span class="hljs-string">grafana/grafana</span><br>  <span class="hljs-attr">user:</span> <span class="hljs-string">&quot;104&quot;</span><br>  <span class="hljs-attr">restart:</span> <span class="hljs-string">always</span><br>  <span class="hljs-attr">links:</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">influxdb:influxsrv</span><br>  <span class="hljs-attr">ports:</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">&quot;3000:3000&quot;</span><br>  <span class="hljs-attr">volumes:</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">grafana_data:/var/lib/grafana</span><br>  <span class="hljs-attr">environment:</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">HTTP_USER=admin</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">HTTP_PASS=admin</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">INFLUXDB_HOST=influxsrv</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">INFLUXDB_PORT=8086</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">INFLUXDB_NAME=cadvisor</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">INFLUXDB_USER=root</span><br>    <span class="hljs-bullet">-</span> <span class="hljs-string">INFLUXDB_PASS=root</span><br></code></pre></td></tr></table></figure>

<p>编写yml后先检查一下，没有任何输出说明配置正常</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker-compose config -q</span><br></code></pre></td></tr></table></figure>
<p>检查没问题后直接部署</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">sudo docker-compose up -d</span><br></code></pre></td></tr></table></figure>

<p>部署成功后的三个容器<br><img src="https://img-blog.csdnimg.cn/bacedae7543b4ff9adf5de9729e0fc05.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>根据yml里的配置，CIG三者服务的Web端口分别为：<br>cAdvisor : 8080<br>InfluxDB: 8083<br>Grafana: 3000</p>
<p>接下来可通过<code>http://宿主机ip:端口号</code>的形式进行访问</p>
<h1 id="参-考-资-料"><a href="#参-考-资-料" class="headerlink" title="参  考  资  料"></a>参  考  资  料</h1><hr>
<p>[1] <a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1gr4y1U7CY?p=78">视频链接</a></p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/Docker/" class="category-chain-item">Docker</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/Docker/">#Docker</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Docker 笔记4 compose 容器编排</div>
      <div>http://example.com/2022/04/09/Docker 笔记4 Compose 容器编排/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年4月9日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/05/06/MongoDB%20%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%20%E5%9F%BA%E4%BA%8EPyMongo%E7%9A%84%E7%94%B5%E5%BD%B1%E5%BD%B1%E8%AF%84%E5%88%86%E6%9E%90%20_%20%E5%AF%B9%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%9C%E8%BF%9B%E8%A1%8C%E5%8F%AF%E8%A7%86%E5%8C%96%E5%B1%95%E7%A4%BA%E4%BB%A5%E5%8F%8A%E5%88%86%E6%9E%90%20_%20%E8%AF%84%E8%AE%BA%E8%AF%8D%E4%BA%91%20_%20%E5%88%86%E6%97%B6%E9%97%B4%E6%AE%B5%E5%88%86%E6%9E%90/" title="MongoDB 项目实战 基于PyMongo的电影影评分析 _ 对数据结果进行可视化展示以及分析 _ 评论词云 _ 分时间段分析">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">MongoDB 项目实战 基于PyMongo的电影影评分析 _ 对数据结果进行可视化展示以及分析 _ 评论词云 _ 分时间段分析</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/04/08/Docker%20%E7%AC%94%E8%AE%B03%20Dockerfile%E6%96%87%E4%BB%B6%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%20_%20Docker%E7%9A%84%E7%BD%91%E7%BB%9C%E6%9C%BA%E5%88%B6%E4%BA%94%E5%A4%A7%E7%BD%91%E7%BB%9C%E6%A8%A1%E5%BC%8F%EF%BC%8Cbridge%E6%A8%A1%E5%BC%8F%E3%80%81host%E6%A8%A1%E5%BC%8F%E3%80%81none%E6%A8%A1%E5%BC%8F%E3%80%81container%E6%A8%A1%E5%BC%8F%E3%80%81%E8%87%AA%E5%AE%9A%E4%B9%89%E6%A8%A1%E5%BC%8F%E7%9A%84%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%8C%BA%E5%88%AB/" title="Docker 笔记3 Dockerfile文件常用命令 _ Docker的网络机制五大网络模式，bridge模式、host模式、none模式、container模式、自定义模式的概念与区别">
                        <span class="hidden-mobile">Docker 笔记3 Dockerfile文件常用命令 _ Docker的网络机制五大网络模式，bridge模式、host模式、none模式、container模式、自定义模式的概念与区别</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
